<template>
  <div class="app-container">
     <el-row :gutter="10" class="mb8"> 
      <el-col :span="1.5">
        <el-button
          v-permisaction="['child:clockLog:remove']"
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="ChildClockLogList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />  
      <!-- <el-table-column label="打卡时间" align="center"   width="100" prop="recordedAt" :show-overflow-tooltip="true" />  -->
      <el-table-column label="就寝时间" align="center"   width="160"  prop="sleep.bedAt" :show-overflow-tooltip="true" />
       <el-table-column label="起床时间" align="center"  width="160" prop="sleep.upAt" :show-overflow-tooltip="true" />
     <el-table-column label="睡眠时长" align="center"  width="100" prop="sleep.sleepDuration" :show-overflow-tooltip="true" />
      <el-table-column label="打卡状态" align="center" prop="clockStatus" :show-overflow-tooltip="true" />
       <el-table-column
        label="跳绳量"
        align="center"
        prop="skippingCount"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope"> 
          <el-button
            v-permisaction="['child:clockLog:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

 
  </div>
</template>

<script>
import {
  listChildClockLog,
  getChildClockLog,
  delChildClockLog,  
} from "@/api/child/clocklog";

export default {
  name: "clocklog",
  props: {
    childId: {
      type: Number,
      default: () => {
        return 0;
      }
    },
    childData: {
      type: Object,
      default: () => {
        return {
          ageNum: undefined,
          avatar: undefined,
          birthday: undefined,
          childId: undefined,
          childType: 1,
          familyCode: undefined,
          height: 0,
          heightDad: 0,
          heightInherit: 0,
          heightMum: 0,
          nickname: undefined,
          sex: 1,
          weight: 0
        };
      }
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 参数表格数据
      configList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      typeOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10, 
        childId: this.childId,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        clockLogId: [
          { required: true, message: "身高id不能为空", trigger: "blur" },
        ],
        childId: [
          { required: true, message: "孩子id不能为空", trigger: "blur" },
        ],
      },
      //数据列表
      ChildClockLogList:[],
    };
  },
  created() {
    this.getList();
  },
   watch: {
    //监听子控件内容的改动,发送给父级组件
    childId: {
      handler(newValue, oldValue) {
        this.getList();
      },
      deep: true,
    },
  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      listChildClockLog(
        this.childId,
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.ChildClockLogList = response.data.list;
        this.total = response.data.count;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        clockLogId: undefined,
        childId: undefined,
        upTime: undefined,
        bedTime: undefined,
        skippingCount: undefined,
         
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageIndex = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加打卡表";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.clockLogId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const clockLogId = row.clockLogId || this.ids;
      getChildClockLog(clockLogId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改打卡表";
      });
    },
    /** 提交按钮 */
    submitForm: function () { 
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.clockLogId || this.ids;
      this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delChildClockLog(Ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
  },
};
</script>